<?php

function chap0_sf_reg()
{
	User::logout();
	
	$username = G::val($_POST, 'username');
	$password = G::val($_POST, 'password');
	$password_repeat = G::val($_POST, 'password-repeat');

	if ( $password != $password_repeat )
	{
		Dao::flash('error', "两次输入的密码不一致");
		redirect(url(ROUTE_HTML_APP, url_sfparams('chap0','reg',array(
				'username'	=> $username,
				'password'	=> $password,
				'password-repeat'	=> $password_repeat,
			))), 0);
	}

	$ret = User::reg($username, $password);
	if ( !$ret['status'] )
	{
		Dao::flash('error', $ret['msg']);
		redirect(url(ROUTE_HTML_APP, url_sfparams('chap0','reg',array(
				'username'	=> $username,
				'password'	=> $password,
				'password-repeat'	=> $password_repeat,
			))), 0);
	}
	Dao::flash('success', "注册成功");
	
	redirect(url(ROUTE_HTML_APP, url_sfparams('chap0','login',array(
			'username'	=> $username,
		))), 0);
}

?>